﻿using SignalProcessLib;
using SignalProcessLib.Model;
using SignalProcessLib.Model.Enum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int len = 65536;
            double[] x = new double[len + 1];
            double[] y = new double[len + 1];
            //Random rd = new Random();

            //for (int i = 0; i < len; i++)
            //{
            //    x[i] = i;
            //    y[i] = rd.NextDouble() * 10;
            //}

            StreamReader file = new System.IO.StreamReader(@"D:\704\project\0.2-Algorithms Library\SignalProcessLib\Test\data\acc.txt");
            string line;
            int counter = 0;
            float ds = 12800.0f / len;
            while ((line = file.ReadLine()) != null)
            {
                System.Console.WriteLine(line);
                x[counter] = counter * ds;
                y[counter] = float.Parse(line) * 9.8;
                //y[counter] = 20 * Math.Log10(float.Parse(line) * 9.8 / VibrationConstant.Acc0);
                counter++;
            }
            Console.WriteLine(counter);
            file.Close();

            DataFormat data = new DataFormat();
            //data.Unit = "dB";
            data.Unit = "加速度(dB)";
            data.X = x;
            data.Y = y;
            double r = new RmsCalculation().Dispathcer(data);
            //double r = new RmsCalculation().SpectrumAmplitude(y);
            //DataFormat df = new UnitConverter().IntegrationDispatcher(data);
            //Console.WriteLine(r);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            float[] a = new float[] { 1, 2, 3, 4, 5, 6 };
            float[] b = new float[] { 1, 2, 3, 4, 5, 6 };
            float[] c = new float[] { 1, 2, 3, 4, 5, 6 };
            List<float[]> ll = new List<float[]>();
            ll.Add(a);
            ll.Add(b);
            ll.Add(c);
            float overlap = 0.66667f;
            float[] rawdata = DigitalSignalProcessing.OverlapSignal(ll, overlap);
            Console.WriteLine();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            float[] r = new float[6];
            //收到第一包数据
            float[] a = new float[] { 1, 2, 3, 4, 5, 6 };
            r = DigitalSignalProcessing.Average(a, r, 1, AverageType.Linear);
            //收到第二包数据
            float[] b = new float[] { 2, 2, 3, 4, 5, 6 };
            r = DigitalSignalProcessing.Average(b, r, 1, AverageType.Linear);
            //收到第三包数据
            float[] c = new float[] { 3, 2, 3, 4, 5, 6 };
            r = DigitalSignalProcessing.Average(b, r, 1, AverageType.Linear);

        }
    }
}
